#!/bin/bash

pack()
{
	echo -e "\033[32mpacking $3 \033[0m"
	texturepacker  \
		--format cocos2d \
		--texture-format pvr2ccz \
		--size-constraints POT \
		--padding 1 \
		--opt RGBA8888 \
		--extrude 1 \
		--enable-rotation \
		--algorithm MaxRects \
		--trim-mode Trim \
		--content-protection '141cb4e9eef90d668f2eae3e26b0d352' \
		$4 \
		--data $1 \
		--sheet $2 \
		$3	
	echo
}

# 打包植物卡
cd ..
mkdir -p res/cards
echo -e "\033[36mstart packing palntcards... \033[0m"
pack "res/cards/cards.plist" "res/cards/cards.pvr.ccz" "cocosstudio/cards" "--trim-sprite-names"

# 打包植物
cd cocosstudio/plants
mkdir -p ../../res/plants
echo -e "\033[36mstart packing plants... \033[0m"
find . ! -name "." -type d | while read dir; do pack "../../res/plants/$dir.plist" "../../res/plants/$dir.pvr.ccz" $dir; done

# 打包僵尸
cd ../zombies
mkdir -p ../../res/zombies
echo -e "\033[36mstart packing zombies...\033[0m"
find . ! -name "." -type d | while read dir; do pack "../../res/zombies/$dir.plist" "../../res/zombies/$dir.pvr.ccz" $dir; done

# 打包 UI
cd ../..
mkdir -p res/ui
echo -e "\033[36mstart packing ui...\033[0m"
source=""
for file in cocosstudio/*.png  cocosstudio/*.jpg
do
	source="$source $file"
done
pack "res/ui/ui.plist" "res/ui/ui.pvr.ccz" "$source"

# ready 动画
pack "res/ui/ready.plist" "res/ui/ready.pvr.ccz" "cocosstudio/ready" 

read -p 输入回车键结束...
exit 0
